package com.htc.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.htc.dlc.R;
import com.htc.dlc.SettingsActivity;
import com.htc.model.dto.SpaChildDTO;
import com.htc.utils.CommonActions;

public class SpaAdapter extends BaseExpandableListAdapter {
	CommonActions ca;
	private Context context;
	private LayoutInflater inflater;
	private ArrayList<SpaChildDTO> spaChild;
	String combineCost;
	String[] splitCost;
	String singleCosts;
	SettingsActivity st = new SettingsActivity();

	public SpaAdapter(Context paramContext, int paramInt,
			ArrayList<SpaChildDTO> paramArrayList) {
		this.context = paramContext;
		this.spaChild = paramArrayList;
		this.inflater = ((LayoutInflater) paramContext
				.getSystemService("layout_inflater"));
		this.ca = new CommonActions(paramContext);
	}

	public Object getChild(int groupPosition, int childPosititon) {
		return null;

	}

	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	public View getChildView(int groupPosition, final int childPosition,
			boolean isLastChild, View convertView, ViewGroup paramViewGroup) {
		if (convertView == null)
			convertView = this.inflater.inflate(R.layout.activity_spa_chidren,
					null);
		TextView txtDescription = (TextView) convertView
				.findViewById(R.id.tv_spa_elv_child_description);
		txtDescription.setTypeface(this.ca.getRailway_Regular());

		if (st.flag == 0) {
			if (((SpaChildDTO) this.spaChild.get(groupPosition)).getSpaDesc()
					.toString() != null)
				txtDescription.setText(((SpaChildDTO) this.spaChild
						.get(groupPosition)).getSpaDesc().toString()
						.replaceAll("\\\\n", "\n"));
		} else if (st.flag == 1) {
			if (((SpaChildDTO) this.spaChild.get(groupPosition)).getSpaDescAr()
					.toString() != null)
				txtDescription.setText(((SpaChildDTO) this.spaChild
						.get(groupPosition)).getSpaDescAr().toString()
						.replaceAll("\\\\n", "\n"));
		}

		singleCosts = "";
		for (int i = 0;; i++) {
			if (i >= this.splitCost.length) {
				TextView localTextView2 = (TextView) convertView
						.findViewById(R.id.tv_spa_elv_child_costfortwo);
				localTextView2.setTypeface(this.ca.getRailway_Regular());
				localTextView2.setText(this.singleCosts);
				return convertView;
			}
			if (this.splitCost[i].length() != 20)
				if (singleCosts != null)
					singleCosts = (singleCosts + splitCost[i] + "\n");

		}
		

	}

	public int getChildrenCount(int groupPosition) {
		return 1;

	}

	public Object getGroup(int groupPosition) {
		return 0;
	}

	public int getGroupCount() {
		return spaChild.size();
	}

	public long getGroupId(int groupPosition) {
		return groupPosition;
	}

	public View getGroupView(int groupPosition, boolean paramBoolean,
			View paramView, ViewGroup paramViewGroup) {
		if (paramView == null)
			paramView = this.inflater.inflate(R.layout.activity_spa_parent,
					null);
		TextView txtTitle = (TextView) paramView
				.findViewById(R.id.tv_spa_elv_parent_title);
		txtTitle.setTypeface(this.ca.getRailway_SemiBold());
		if (st.flag == 0) {
			txtTitle.setText(((SpaChildDTO) this.spaChild.get(groupPosition))
					.getSecTitle());
		} else if (st.flag == 1) {
			txtTitle.setText(((SpaChildDTO) this.spaChild.get(groupPosition))
					.getSecTitleAr());
		}

		TextView txtTime = (TextView) paramView
				.findViewById(R.id.tv_spa_elv_parent_time);
		txtTime.setTypeface(this.ca.getRailway_Regular());
		txtTime.setText(((SpaChildDTO) this.spaChild.get(groupPosition))
				.getSpaTimeDuration());
		combineCost = ((SpaChildDTO) this.spaChild.get(groupPosition))
				.getSpaPackagePrice();
		if (combineCost != null)
			splitCost = this.combineCost.split(",");
		return paramView;
	}

	public boolean hasStableIds() {
		return true;
	}

	public boolean isChildSelectable(int paramInt1, int paramInt2) {
		return true;
	}

	public void refreshData(ArrayList<SpaChildDTO> paramArrayList) {
		this.spaChild = paramArrayList;
		notifyDataSetChanged();
	}
}